package com.example.rentingcockpit.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.rentingcockpit.service.impl.RentingServiceImpl;
import com.fasterxml.jackson.databind.util.JSONPObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.jws.WebParam;
import java.util.Map;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class ViewController {

    @Autowired
    private RentingServiceImpl rentingService;

    @RequestMapping("/view")
    public ModelAndView view() {
        ModelAndView modelAndView = new ModelAndView("/views/index.html");
        modelAndView.addObject("applianceBeijing", rentingService.radarApplianceProportion("北京"));
        modelAndView.addObject("applianceShanghai", rentingService.radarApplianceProportion("上海"));
        modelAndView.addObject("applianceShenzhen", rentingService.radarApplianceProportion("深圳"));
        modelAndView.addObject("furnitureBeijing", rentingService.radarFurnitureProportion("北京"));
        modelAndView.addObject("furnitureShanghai", rentingService.radarFurnitureProportion("上海"));
        modelAndView.addObject("furnitureShenzhen", rentingService.radarFurnitureProportion("深圳"));
        modelAndView.addObject("BJ_Changping", rentingService.sunburstDistrict("北京", "昌平"));
        modelAndView.addObject("BJ_Chaoyang", rentingService.sunburstDistrict("北京", "朝阳"));
        modelAndView.addObject("BJ_Daxing", rentingService.sunburstDistrict("北京", "大兴"));
        modelAndView.addObject("BJ_Dongcheng", rentingService.sunburstDistrict("北京", "东城"));
        modelAndView.addObject("BJ_Fangshan", rentingService.sunburstDistrict("北京", "房山"));
        modelAndView.addObject("BJ_Fengtai", rentingService.sunburstDistrict("北京", "丰台"));
        modelAndView.addObject("BJ_Haidian", rentingService.sunburstDistrict("北京", "海淀"));
        modelAndView.addObject("BJ_Huairou", rentingService.sunburstDistrict("北京", "怀柔"));
        modelAndView.addObject("BJ_Mentougou", rentingService.sunburstDistrict("北京", "门头沟"));
        modelAndView.addObject("BJ_Shijingshan", rentingService.sunburstDistrict("北京", "石景山"));
        modelAndView.addObject("BJ_Shunyi", rentingService.sunburstDistrict("北京", "顺义"));
        modelAndView.addObject("BJ_Tongzhou", rentingService.sunburstDistrict("北京", "通州"));
        modelAndView.addObject("BJ_Xicheng", rentingService.sunburstDistrict("北京", "西城"));
        modelAndView.addObject("SH_Baoshan", rentingService.sunburstDistrict("上海", "宝山"));
        modelAndView.addObject("SH_Fengxian", rentingService.sunburstDistrict("上海", "奉贤"));
        modelAndView.addObject("SH_Hongkou", rentingService.sunburstDistrict("上海", "虹口"));
        modelAndView.addObject("SH_Huangpu", rentingService.sunburstDistrict("上海", "黄埔"));
        modelAndView.addObject("SH_Jiading", rentingService.sunburstDistrict("上海", "嘉定"));
        modelAndView.addObject("SH_Jingan", rentingService.sunburstDistrict("上海", "静安"));
        modelAndView.addObject("SH_Minhang", rentingService.sunburstDistrict("上海", "闵行"));
        modelAndView.addObject("SH_Pudong", rentingService.sunburstDistrict("上海", "浦东"));
        modelAndView.addObject("SH_Putuo", rentingService.sunburstDistrict("上海", "普陀"));
        modelAndView.addObject("SH_Xuhui", rentingService.sunburstDistrict("上海", "徐汇"));
        modelAndView.addObject("SH_Yangpu", rentingService.sunburstDistrict("上海", "杨浦"));
        modelAndView.addObject("SH_Changning", rentingService.sunburstDistrict("上海", "长宁"));
        modelAndView.addObject("SZ_Baoan", rentingService.sunburstDistrict("深圳", "宝安"));
        modelAndView.addObject("SZ_Buji", rentingService.sunburstDistrict("深圳", "布吉"));
        modelAndView.addObject("SZ_Futian", rentingService.sunburstDistrict("深圳", "福田"));
        modelAndView.addObject("SZ_Guangming", rentingService.sunburstDistrict("深圳", "光明"));
        modelAndView.addObject("SZ_Longgang", rentingService.sunburstDistrict("深圳", "龙岗"));
        modelAndView.addObject("SZ_Longhua", rentingService.sunburstDistrict("深圳", "龙华"));
        modelAndView.addObject("SZ_Luohu", rentingService.sunburstDistrict("深圳", "罗湖"));
        modelAndView.addObject("SZ_Nanshan", rentingService.sunburstDistrict("深圳", "南山"));
        modelAndView.addObject("SZ_Yantian", rentingService.sunburstDistrict("深圳", "盐田"));
        modelAndView.addObject("total", rentingService.digitalAvailability("全部"));
        ArrayList<Integer> cityAvailability = new ArrayList<>();
        cityAvailability.add(rentingService.digitalAvailability("北京"));
        cityAvailability.add(rentingService.digitalAvailability("上海"));
        cityAvailability.add(rentingService.digitalAvailability("深圳"));
        modelAndView.addObject("cityList", cityAvailability);
        List<List<Integer>> roomBeijing=rentingService.pieRoomProportion("北京");
        List<List<Integer>> roomShanghai=rentingService.pieRoomProportion("上海");
        List<List<Integer>> roomShenzhen=rentingService.pieRoomProportion("深圳");
        modelAndView.addObject("BJ_bedroom_1",roomBeijing.get(0).get(0));
        modelAndView.addObject("BJ_bedroom_2",roomBeijing.get(0).get(1));
        modelAndView.addObject("BJ_bedroom_3",roomBeijing.get(0).get(2));
        modelAndView.addObject("BJ_bathroom_0",roomBeijing.get(1).get(0));
        modelAndView.addObject("BJ_bathroom_1",roomBeijing.get(1).get(1));
        modelAndView.addObject("BJ_bathroom_2",roomBeijing.get(1).get(2));
        modelAndView.addObject("BJ_bathroom_3",roomBeijing.get(1).get(3));
        modelAndView.addObject("BJ_hall_0",roomBeijing.get(2).get(0));
        modelAndView.addObject("BJ_hall_1",roomBeijing.get(2).get(1));
        modelAndView.addObject("BJ_hall_2",roomBeijing.get(2).get(2));
        modelAndView.addObject("BJ_hall_3",roomBeijing.get(2).get(3));
        modelAndView.addObject("SH_bedroom_1",roomShanghai.get(0).get(0));
        modelAndView.addObject("SH_bedroom_2",roomShanghai.get(0).get(1));
        modelAndView.addObject("SH_bedroom_3",roomShanghai.get(0).get(2));
        modelAndView.addObject("SH_bathroom_0",roomShanghai.get(1).get(0));
        modelAndView.addObject("SH_bathroom_1",roomShanghai.get(1).get(1));
        modelAndView.addObject("SH_bathroom_2",roomShanghai.get(1).get(2));
        modelAndView.addObject("SH_bathroom_3",roomShanghai.get(1).get(3));
        modelAndView.addObject("SH_hall_0",roomShanghai.get(2).get(0));
        modelAndView.addObject("SH_hall_1",roomShanghai.get(2).get(1));
        modelAndView.addObject("SH_hall_2",roomShanghai.get(2).get(2));
        modelAndView.addObject("SH_hall_3",roomShanghai.get(2).get(3));
        modelAndView.addObject("SZ_bedroom_1",roomShenzhen.get(0).get(0));
        modelAndView.addObject("SZ_bedroom_2",roomShenzhen.get(0).get(1));
        modelAndView.addObject("SZ_bedroom_3",roomShenzhen.get(0).get(2));
        modelAndView.addObject("SZ_bathroom_0",roomShenzhen.get(1).get(0));
        modelAndView.addObject("SZ_bathroom_1",roomShenzhen.get(1).get(1));
        modelAndView.addObject("SZ_bathroom_2",roomShenzhen.get(1).get(2));
        modelAndView.addObject("SZ_bathroom_3",roomShenzhen.get(1).get(3));
        modelAndView.addObject("SZ_hall_0",roomShenzhen.get(2).get(0));
        modelAndView.addObject("SZ_hall_1",roomShenzhen.get(2).get(1));
        modelAndView.addObject("SZ_hall_2",roomShenzhen.get(2).get(2));
        modelAndView.addObject("SZ_hall_3",roomShenzhen.get(2).get(3));

        modelAndView.addObject("barchartPrice",rentingService.barchartPrice());
        modelAndView.addObject("pictogramFloor",rentingService.pictogramFloor());

        return modelAndView;
    }

    @RequestMapping("/map")
    @CrossOrigin("*")
    public JSONObject mapLocation(){
        return rentingService.mapLocation();
    }
}
